<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //如果创建一个实例对象的时候没有new会发生什么 ?
        var Book = function (id, name, price) {
                //公有属性
                this.id = id
                this.price = price
                this.name = name
        }   
        //创建实例对象
        var book = Book(1,'了不起的比尔盖茨',55)
        console.log(book)
        console.log(window.id)
        console.log(window.name)
        console.log(window.price)
        //发现居然给全局变量增加了三个变量
        //采用安全模式
        var Student = function (stuid, name, stuclass) {
            if (this instanceof Student){
                this.stuid = stuid
                this.name = name
                this.stuclass = stuclass
            }else{
                return new Student(stuid, name, stuclass)
            }
        }
        var stu1 = Student (1,'小明',38)
        var stu2 = new Student (2,'小茨',65)
        console.log(stu1)
        console.log(stu2)
        console.log(window.stuid)
    </script>
</body>
</html>